<?php

class InboxController extends Controller {

  public $content;

  public function init() {

    if (user()->getUserProperty('username') == '')
      $this->redirect(FRONT_SITE_URL);
  }

  public function actionIndex() {
    
    $this->layout = 'main_after_login';
    //$tab = array();
    $this->content['addCss'] = array('connect.css');
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/peoplemedia_002.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/Inbox.js", CClientScript::POS_BEGIN);
    $currentPage = isset($_GET['currentPage'])?$_GET['currentPage']:1;
    $data = array();
    $data['noRecord'] = '';
    $totalUserView = mUserLike::model()->findAll('user_id=:user_id', 
                                      array(':user_id'=>user()->getUserProperty('user_id')));
    $rsUserView = mUserLike::model()->getUserLikeWithPagination(user()->getUserProperty('user_id'),($currentPage-1)*10,10);
    $data['filter'] = 0;
    if(count($totalUserView)<=0){
      $data['noRecord'] = $this->getMessageWithRecordNullInGetSentView();
    }
    $data['pagination'] = $this->pagesListLimit(count($totalUserView),10,2,1);
    $view = 'GetSentLikes';
    $this->render($view,array(
                            'currentPage'=>$currentPage,
                            'totalUserView'=>$totalUserView,
                            'rsUserView'=>$rsUserView,
                            'data'=>$data
                  ));
    
  }
  
  public function actionMessages() {
    
    $this->layout = 'main_after_login';
    //$tab = array();
    $this->content['addCss'] = array('connect.css');
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/peoplemedia_002.js", CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/js1/Inbox.js", CClientScript::POS_BEGIN);
    $currentPage = isset($_GET['currentPage'])?$_GET['currentPage']:1;
    $data = array();
    $data['noRecord'] = '';
    $totalUserView = mUserMessage::model()->findAll('user_id=:user_id', 
                                      array(':user_id'=>user()->getUserProperty('user_id')));
    $rsUserView = mUserMessage::model()->getUserMessageWithPagination(user()->getUserProperty('user_id'),($currentPage-1)*10,10);
    $data['filter'] = 0;
    if(count($totalUserView)<=0){
      $data['noRecord'] = $this->getMessageWithRecordNullInGetSentMessage();
    }
    $data['pagination'] = $this->pagesListLimit(count($totalUserView),10,2,1);
    $view = 'GetSentFavorites';
    $this->render($view,array(
                            'currentPage'=>$currentPage,
                            'totalUserView'=>$totalUserView,
                            'rsUserView'=>$rsUserView,
                            'data'=>$data
                  ));
    
  }
  
  function pagesListLimit($totalRows , $pageSize = 10, $offset = 2,$currentPage1=1){
    $result['html'] = '';
    $result['htmlBottom'] = '';
    $searchleft = ''; $searchright='';
	if ($totalRows<=0) return $result;
    $totalPages = ceil($totalRows/$pageSize);
    if ($totalPages <= 1)
      return $result;
    $currentURL = $_SERVER['PHP_SELF'];
    
    $currentPage = $currentPage1;
    $querystring = "";
    foreach ($_GET as $k => $v) {
      if ($k != 'pageNum')
        $querystring.= "&{$k}={$v}";
    }
    $querystring = substr($querystring, 1);

    $links='<div id="paginationsearchcenter">';
    $from = $currentPage - $offset;
    $to = $currentPage + $offset;
    if ($from <= 0) {
      $from = 1;
      $to = $offset * 2;
    }
    if ($to > $totalPages) {
      $to = $totalPages;
    }
    if($currentPage==1){ 
          $searchleft = '<div id="paginationsearchleft">
            <a href="javascript:void(0);" class="button_style buttonunavailable" title="Previous">
                Previous</a></div>';
          $links.='<a href="javascript:void(0);" >
                <img src="'.FRONT_SITE_URL.'www/images/images1/leftarrow.png" class="arrowunavailable" border="0" alt="" /></a>';
    }else if($currentPage>1){
          $searchleft = '<div id="paginationsearchleft">
            <a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage-1).', 10, '.$totalRows.');" class="button_style" title="Previous">
                Previous</a></div>';
          $links.='<a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage-1).', 10, '.$totalRows.');">
                <img src="'.FRONT_SITE_URL.'www/images/images1/leftarrow.png" class="" border="0" alt="" /></a>';
    }
    for ($j = $from; $j <= $to; $j++) {
      if ($j == $currentPage)
        $links = $links . '<span class="paginationon">'.($j).'</span>';
      else {        
        $links.='<a href="javascript:void(0);" onclick="PeopleMedia.Connect.paginate('.($j).', 10, '.$totalRows.');">'.$j.'</a>';
      }
    }
    if($totalPages==$currentPage){
          $searchright = '<div id="paginationsearchright">
            <a href="javascript:void(0);" class="button_style buttonunavailable" title="Next">
                Next</a>
            </div>';
          $links .= '<a href="javascript:void(0);">
                  <img src="'.FRONT_SITE_URL.'www/images/images1/rightarrow.png" class="arrowunavailable" border="0" alt="" /></a>';
    }else{
          $searchright = '<div id="paginationsearchright">
            <a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage+1).', 10, '.$totalRows.');" class="button_style" title="Next">
                Next</a>
    </div>';
          $links .= '<a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage+1).', 10, '.$totalRows.');">
                  <img src="'.FRONT_SITE_URL.'www/images/images1/rightarrow.png" border="0" alt="" /></a>';
    }
    $links .='</div>';
    $result['html'] = $links;
    $result['htmlBottom'] = $searchleft.$links.$searchright;
    return $result;
  }
  
  public function getMessageWithRecordNullInGetSentView(){
    $html = '<div id="ViewsListContent" class="yescontentmiddlerow" style="display: block;">
              <div id="connectViewsMemberList">
              </div>
                                <div class="nomessagesarea">
                                <h1>You have not Liked any profiles yet.</h1>
                                <p><strong>Quick Tip:</strong> Wow! You haven’t checked anyone out yet. Now is the time. Get started with a local search.</p>
                                <p class="nomessagesareaa"><a title="Search Now" class="button_style" href="'.app()->createAbsoluteUrl('search#Sortby=MyDefault').'">Search Now</a></p>
                                </div>

                            <div style="display:none" id="LoadingResultsDiv" class="resultsloadingoverlay">
                                <div class="resultsloading bgcolor-main">
                                    <h1>
                                        Sending your message...</h1>
                                    <div class="loadinggraphic">
                                        <img alt="" src="'.FRONT_SITE_URL.'www/images/images1/waitwheel.gif">
                                    </div>
                                    <p class="clearfix">
                                        &nbsp;</p>
                                </div>
                            </div></div>';
    return $html;
  }
  
  public function getMessageWithRecordNullInGetSentMessage(){
    $html = '<div id="ViewsListContent" class="yescontentmiddlerow" style="display: block;">
              <div id="connectViewsMemberList">
              </div>
                                <div class="nomessagesarea">
                                <h1>You have not Messaged any profiles yet.</h1>
                                <p><strong>Quick Tip:</strong> Wow! You haven’t checked anyone out yet. Now is the time. Get started with a local search.</p>
                                <p class="nomessagesareaa"><a title="Search Now" class="button_style" href="'.app()->createAbsoluteUrl('search#Sortby=MyDefault').'">Search Now</a></p>
                                </div>

                            <div style="display:none" id="LoadingResultsDiv" class="resultsloadingoverlay">
                                <div class="resultsloading bgcolor-main">
                                    <h1>
                                        Sending your message...</h1>
                                    <div class="loadinggraphic">
                                        <img alt="" src="'.FRONT_SITE_URL.'www/images/images1/waitwheel.gif">
                                    </div>
                                    <p class="clearfix">
                                        &nbsp;</p>
                                </div>
                            </div></div>';
    return $html;
  }
  
  public function actionDeleteConnectItem(){
    $result['status'] = 'Success';
    if(isset($_POST['encryptedMemberId']) && isset($_POST['filter']) && isset($_POST['tab'])){
      if($_POST['tab'] == 1 && $_POST['filter'] == 0){
        mUserMessage::model()->deleteAll('user_id=:user_id and user_messaged=:user_messaged', 
                                              array(':user_id'=>user()->getUserProperty('user_id'),
                                                    ':user_messaged'=>$_POST['encryptedMemberId']));
      }else if($_POST['tab'] == 1 && $_POST['filter'] == 1){
        mUserMessage::model()->deleteAll('user_id=:user_id and user_messaged=:user_messaged', 
                                              array(':user_id'=>$_POST['encryptedMemberId'],
                                                    ':user_messaged'=>user()->getUserProperty('user_id')));
      }else if($_POST['tab'] == 2 && $_POST['filter'] == 0){
        mUserLike::model()->deleteAll('user_id=:user_id and user_id_liked=:user_id_liked', 
                                              array(':user_id'=>user()->getUserProperty('user_id'),
                                                    ':user_id_liked'=>$_POST['encryptedMemberId']));
      }else if($_POST['tab'] == 2 && $_POST['filter'] == 1){
        mUserLike::model()->deleteAll('user_id=:user_id and user_id_liked=:user_id_liked', 
                                              array(':user_id'=>$_POST['encryptedMemberId'],
                                                    ':user_id_liked'=>user()->getUserProperty('user_id')));
      }
      
    }
    echo CJSON::encode($result);
    YII::app()->end();
  }
  
  public function actionDeleteMultipleConnectItems(){
    $result['status'] = 'Success';
    
    if(isset($_POST['encryptedMemberIds']) && isset($_POST['filter']) && isset($_POST['tab'])){
      if($_POST['tab'] == 1 && $_POST['filter'] == 0){
        $encryptedMemberIds = json_decode($_POST['encryptedMemberIds'], true);
        $encryptedMemberIds = implode(',', $encryptedMemberIds);
        mUserMessage::model()->deleteAll('user_id=:user_id and user_messaged in ('. $encryptedMemberIds.')', 
                                              array(':user_id'=>user()->getUserProperty('user_id')));
      }else if($_POST['tab'] == 1 && $_POST['filter'] == 1){
        $encryptedMemberIds = json_decode($_POST['encryptedMemberIds'], true);
        $encryptedMemberIds = implode(',', $encryptedMemberIds);
        mUserMessage::model()->deleteAll('user_id in ('.$encryptedMemberIds.') and user_messaged=:user_messaged', 
                                              array(':user_messaged'=>user()->getUserProperty('user_id')));
      }else if($_POST['tab'] == 2 && $_POST['filter'] == 0){
        $encryptedMemberIds = json_decode($_POST['encryptedMemberIds'], true);
        $encryptedMemberIds = implode(',', $encryptedMemberIds);
        mUserLike::model()->deleteAll('user_id=:user_id and user_id_liked in ('. $encryptedMemberIds.')', 
                                              array(':user_id'=>user()->getUserProperty('user_id')));
      }else if($_POST['tab'] == 2 && $_POST['filter'] == 1){
        $encryptedMemberIds = json_decode($_POST['encryptedMemberIds'], true);
        $encryptedMemberIds = implode(',', $encryptedMemberIds);
        mUserLike::model()->deleteAll('user_id in ('.$encryptedMemberIds.') and user_id_liked=:user_id_liked', 
                                              array(':user_id_liked'=>user()->getUserProperty('user_id')));
      }
    }
    echo CJSON::encode($result);
    YII::app()->end();
  }
  
  public function actionGetSentViews(){
    $result['status'] = 'Error';
    if(isset($_GET['currentPage'])){
      $result['status'] = 'Success';
      $result['html'] = '';
      $result['totalRecords'] = 0;
      //array(3) { ["status"]=> string(7) "Success" ["html"]=> string(67594) " " ["totalRecords"]=> int(106) }  
      $currentPage = $_GET['currentPage'];
      $totalUserView = mUserLike::model()->findAll('user_id=:user_id', 
                                      array(':user_id'=>user()->getUserProperty('user_id')));
      $rsUserView = mUserLike::model()->getUserLikeWithPagination(user()->getUserProperty('user_id'),($currentPage-1)*10,10);
      
      if(count($totalUserView)>0){
        $result['html'] = $this->getSelectAll('Views',2,0);
        $filter = 0;
        $result['html'] .= $this->getHtmlMemberList($rsUserView,$totalUserView,$totalUserView,'Views',2,$filter,'connectviews');
        $result['totalRecords'] = count($totalUserView);
      }else{
        $result['html'] = $this->getMessageWithRecordNullInGetSentView();
      } 
    }
    echo CJSON::encode($result);
    YII::app()->end();
  }
  
  public function actionGetReceivedViews(){
    $result['status'] = 'Error';
    if(isset($_GET['currentPage'])){
      $result['status'] = 'Success';
      $result['html'] = '';
      $result['totalRecords'] = 0;
      //array(3) { ["status"]=> string(7) "Success" ["html"]=> string(67594) " " ["totalRecords"]=> int(106) }  
      $currentPage = $_GET['currentPage'];
      $totalUserView = mUserLike::model()->findAll('user_id_liked=:user_id_liked and mutual = 0', 
                                    array(':user_id_liked'=>user()->getUserProperty('user_id')));
      $rsUserView = mUserLike::model()->getUserLikedWithPagination(user()->getUserProperty('user_id'),($currentPage-1)*10,10);
      
      if(count($totalUserView)>0){
        $result['html'] = $this->getSelectAll('Views',2,1);
        $filter = 1;
        $result['html'] .= $this->getHtmlMemberList($rsUserView,$totalUserView,$totalUserView,'Views',2,$filter,'connectviews');
        $result['totalRecords'] = count($totalUserView);
      }else{
        $result['html'] = $this->getMessageWithRecordNullInGetSentView();
      } 
    }
    echo CJSON::encode($result);
    YII::app()->end();
  }
  
  public function actionGetSentFavorites(){
    $result['status'] = 'Error';
    if(isset($_GET['currentPage'])){
      $result['status'] = 'Success';
      $result['html'] = '';
      $result['totalRecords'] = 0;
      //array(3) { ["status"]=> string(7) "Success" ["html"]=> string(67594) " " ["totalRecords"]=> int(106) }  
      $currentPage = $_GET['currentPage'];
      $totalUserView = mUserMessage::model()->findAll('user_id=:user_id', 
                                      array(':user_id'=>user()->getUserProperty('user_id')));
      $rsUserView = mUserMessage::model()->getUserMessageWithPagination(user()->getUserProperty('user_id'),($currentPage-1)*10,10);
      
      if(count($totalUserView)>0){
        $result['html'] = $this->getSelectAll('Favorites',1,0);
        $filter = 0;
        $result['html'] .= $this->getHtmlMessageMemberList($rsUserView,$totalUserView,$totalUserView,'Favorites',1,$filter,'connectfavs');
        $result['totalRecords'] = count($totalUserView);
      }else{
        $result['html'] = $this->getMessageWithRecordNullInGetSentMessage();
      } 
    }
    echo CJSON::encode($result);
    YII::app()->end();
  }
  
  public function actionGetReceivedFavorites(){
    $result['status'] = 'Error';
    if(isset($_GET['currentPage'])){
      $result['status'] = 'Success';
      $result['html'] = '';
      $result['totalRecords'] = 0;
      //array(3) { ["status"]=> string(7) "Success" ["html"]=> string(67594) " " ["totalRecords"]=> int(106) }  
      $currentPage = $_GET['currentPage'];
      $totalUserView = mUserMessage::model()->findAll('user_messaged=:user_messaged', 
                                    array(':user_messaged'=>user()->getUserProperty('user_id')));
      $rsUserView = mUserMessage::model()->getUserMessagedWithPagination(user()->getUserProperty('user_id'),($currentPage-1)*10,10);
      
      if(count($totalUserView)>0){
        $result['html'] = $this->getSelectAll('Favorites',1,1);
        $filter = 1;
        $result['html'] .= $this->getHtmlMessageMemberList($rsUserView,$totalUserView,$totalUserView,'Favorites',1,$filter,'connectfavs');
        $result['totalRecords'] = count($totalUserView);
      }else{
        $result['html'] = $this->getMessageWithRecordNullInGetSentMessage();
      } 
    }
    echo CJSON::encode($result);
    YII::app()->end();
  }
  
  public function actionRefreshPagination(){//page   totalRecords
    $result = array();
    $result['html'] = '';
    $result['htmlBottom'] = '';
    $result['status'] = 'Success';
    $searchleft = ''; $searchright='';
    $totalRows = isset($_GET['totalRecords'])?$_GET['totalRecords']:0;
    
    $pageSize = 10;
    $offset = 2;
	if ($totalRows<=0){
      echo CJSON::encode($result);
      Yii::app()->end();
    }
    $totalPages = ceil($totalRows/$pageSize);
    if ($totalPages <= 1){
      echo CJSON::encode($result);
      Yii::app()->end();
    }
    
    $currentPage = isset($_GET['page'])?$_GET['page']:1;
    $querystring = "";
    foreach ($_GET as $k => $v) {
      if ($k != 'pageNum')
        $querystring.= "&{$k}={$v}";
    }
    $querystring = substr($querystring, 1);

    $links='<div id="paginationsearchcenter">';
    $from = $currentPage - $offset;
    $to = $currentPage + $offset;
    if ($from <= 0) {
      $from = 1;
      $to = $offset * 2;
    }
    if ($to > $totalPages) {
      $to = $totalPages;
    }
    if($currentPage==1){ 
          $searchleft = '<div id="paginationsearchleft">
            <a href="javascript:void(0);" class="button_style buttonunavailable" title="Previous">
                Previous</a></div>';
          $links.='<a href="javascript:void(0);" >
                <img src="'.FRONT_SITE_URL.'www/images/images1/leftarrow.png" class="arrowunavailable" border="0" alt="" /></a>';
    }else if($currentPage>1){
          $searchleft = '<div id="paginationsearchleft">
            <a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage-1).', 10, '.$totalRows.');" class="button_style" title="Previous">
                Previous</a></div>';
          $links.='<a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage-1).', 10, '.$totalRows.');">
                <img src="'.FRONT_SITE_URL.'www/images/images1/leftarrow.png" class="" border="0" alt="" /></a>';
    }
    for ($j = $from; $j <= $to; $j++) {
      if ($j == $currentPage)
        $links = $links . '<span class="paginationon">'.($j).'</span>';
      else {        
        $links.='<a href="javascript:void(0);" onclick="PeopleMedia.Connect.paginate('.($j).', 10, '.$totalRows.');">'.$j.'</a>';
      }
    }
    if($totalPages==$currentPage){
          $searchright = '<div id="paginationsearchright">
            <a href="javascript:void(0);" class="button_style buttonunavailable" title="Next">
                Next</a>
            </div>';
          $links .= '<a href="javascript:void(0);">
                  <img src="'.FRONT_SITE_URL.'www/images/images1/rightarrow.png" class="arrowunavailable" border="0" alt="" /></a>';
    }else{
          $searchright = '<div id="paginationsearchright">
            <a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage+1).', 10, '.$totalRows.');" class="button_style" title="Next">
                Next</a>
    </div>';
          $links .= '<a href="javascript:void(0);" onclick=" PeopleMedia.Connect.paginate('.($currentPage+1).', 10, '.$totalRows.');">
                  <img src="'.FRONT_SITE_URL.'www/images/images1/rightarrow.png" border="0" alt="" /></a>';
    }
    $links .='</div>';
    $result['html'] = $links;
    $result['htmlBottom'] = $searchleft.$links.$searchright;
    
    echo CJSON::encode($result);
    Yii::app()->end();
  }
  
  public function actionRefreshSubHeaderCounts(){
    $strJson = '{"status":"Success","html":"\r\n\r\n            \u003cp class=\"\"\u003e\u003ca href=\"/v3/messages/?start=1\u0026amp;Folder=Inbox\u0026amp;sortcol=message\u0026amp;sortdir=DESC\u0026amp;upn=4\"\u003e\u003cspan class=\"headercountstotalvalue\"\u003eMessages\u003c/span\u003e\u003c/a\u003e\r\n            \u003c/p\u003e\r\n            \u003cp class=\"\"\u003e\u003ca href=\"/v3/connect/connectlist?tab=2\u0026amp;filter=1\"\u003e\u003cspan class=\"headercountstotalvalue\"\u003eViewed Me\u003c/span\u003e\u003c/a\u003e\r\n            \u003c/p\u003e\r\n            \u003cp class=\"\"\u003e\u003ca href=\"/v3/connect/connectlist?tab=1\u0026amp;filter=1\u0026amp;upn=5\"\u003e\u003cspan class=\"headercountstotalvalue\"\u003eFavorited Me\u003c/span\u003e\u003c/a\u003e\r\n            \u003c/p\u003e\r\n            \u003cp class=\"\"\u003e\u003ca href=\"/v3/messages/?start=1\u0026amp;Folder=Inbox\u0026amp;sortcol=flirt\u0026amp;sortdir=DESC\u0026amp;upn=6\"\u003e\u003cspan class=\"headercountstotalvalue\"\u003eFlirted With Me\u003c/span\u003e\u003c/a\u003e\r\n            \u003c/p\u003e\r\n            \u003cp class=\"\"\u003e\u003ca href=\"/v3/messages/?start=1\u0026amp;Folder=Inbox\u0026amp;sortcol=like\u0026amp;sortdir=DESC\u0026amp;upn=67\"\u003e\u003cspan class=\"headercountstotalvalue\"\u003eComment:\u0026nbsp;1\u0026nbsp;\u003c/span\u003e\u003c/a\u003e\r\n                \u003ca class=\"headercountsnewlink\" href=\"/v3/messages/?start=1\u0026amp;Folder=Inbox\u0026amp;sortcol=like\u0026amp;sortdir=DESC\u0026amp;upn=67\"\u003e(\u003cspan class=\"headercountsnewvalue\" \u003e1\u0026nbsp;New\u003c/span\u003e)\u003c/a\u003e\r\n            \u003c/p\u003e\r\n            \u003cp class=\"pnoborder\"\u003e\u003ca href=\"/v3/profile/todaysmatches\"\u003e\u003cspan class=\"headercountstotalvalue\"\u003eToday\u0026#39;s Matches\u003c/span\u003e\u003c/a\u003e\r\n                \u003ca class=\"headercountsnewlink\" href=\"/v3/profile/todaysmatches\"\u003e(\u003cspan class=\"headercountsnewvalue\" \u003e5\u0026nbsp;New\u003c/span\u003e)\u003c/a\u003e\r\n            \u003c/p\u003e\r\n","display":true}';
    echo $strJson;
    Yii::app()->end();
  }
  
  public function actionRefreshPageCounts(){
    $strJson = '{"status":"Success","incomingnew":0,"mutualnew":0,"totalnew":0,"connectTotal":0,"yesvotes":-1,"favorites":-1,"views":0}';
    echo $strJson;
    Yii::app()->end();
  }
  
  public function getSelectAll($tab,$tabEnum,$filter){
    $selectall='<div class="inboxcontenttoprow2">
          <div class="inboxcontenttoprow2col1">
            <input name="" id="selectAllCheckBox'.$tab.'" value="" onclick="PeopleMedia.Connect.selectAllDeleteCheckBoxes(\''.$tab.'\')" type="checkbox">
            <p><a href="#" onclick="PeopleMedia.Connect.clickSelectArea(\''.$tab.'\')">Select All</a></p>
          </div>
          <div class="inboxcontenttoprow2col2"> <a title="Delete" class="button_style_send" href="#" onclick="PeopleMedia.Connect.deleteSelectedMembers(\''.$tab.'\', '.$tabEnum.', '.$filter.', 1);">Delete</a> </div>
        </div>';
    return $selectall;
  }
  public function getHtmlMemberList($rsUserView,$totalUserView,$currentPage,$tab,$tabEnum,$filter,$connect){
    $watched = 'Liked';
    $img_watched = 'facebooklikeicon.png';
    $for_delete = 'View';
    if($tab == 'Favorites'){
      $watched = 'Messaged';
      $img_watched = 'staricon.png';
      $for_delete = 'Favorite';
    }else if($tab == 'Yeses'){
      $watched = 'Yesed';
      $img_watched = 'checkicon.png';
      $for_delete = 'Yes';
    }
    $html = '<div id="connect'.$tab.'MemberList">';
    $count = 0;
    
    foreach($rsUserView as $item):
      $link_img = FRONT_SITE_URL . 'www/images/images1/noPhoto-1.gif';
      if ($item['link_img'] != null) 
        $link_img = FRONT_SITE_URL. 'www/uploads/photos/thumbs/thumb_'. $item['link_img']; 
      else {
        $link_img = $item['gender'] == 'male' ? FRONT_SITE_URL . 'www/images/images1/noPhoto-1.gif' : FRONT_SITE_URL . 'www/images/images1/noPhoto-2.gif';
      }
      $user_favorite = $item['user_favorited']!=null?'display:none':'display:inline';
      $user_un_favorite = $item['user_favorited']==null?'display:none':'display:inline';
      $html.='<div id="connectItem'.$count.$tab.'" class="profilerepeat ">
            <div class="profilerepeatcol0">
              <input type="checkbox" onchange="PeopleMedia.Connect.selectSingleDeleteCheckBox(\''.$tab.'\', '.$count.')" value="" class="deleteCheckbox'.$tab.'" id="checkboxDelete'.$count.$tab.'" name="'.$item['user_id'].'">
            </div>
            <div class="profilerepeatcol1 ">

              <div id="profileoverlayplace">
              </div>
              <a title="bighuggs1" href="'. FRONT_SITE_URL.'user/profile/viewprofile?profile='.$item['user_id'].'">
                                <img border="0" class="userpic" title="tuong" src="'.$link_img.'">
              </a>
            </div>
            <div class="profilerepeatcol2">
              <div class="profilerepeatcol2row1">
                <p><a href="'. FRONT_SITE_URL.'user/profile/viewprofile?profile='.$item['user_id'].'">'.$item['username'].'</a></p>
                <img src="'.FRONT_SITE_URL.'www/images/images1/'.$img_watched.'" title="Viewed">
                <p class="lightgraytext timestampcl">'.$watched.': '.changedDateFormat($item['date_view'],'d-m-Y').'</p>
              </div>


              <div class="profilerepeatcol2row2">

                <p>'.calculateYearOld($item['birthdate']).' | '.$item['country_name'].'                                              </p>
              </div>

              <div class="profilerepeatcol2row3">
                <p><span class="lightgraytext">A little about me: </span>
                  '.$item['greeting1'].'
                  </p>
              </div>

              <div class="profilerepeatcol2row4">
                
                <a style="'.$user_favorite.'" onclick="PeopleMedia.Connect.toggleFavorite(true, '.$item['user_id'].', '.$count.', \''.$tab.'\', \''.$connect.'\')" title="Save as Favorite" class="SaveToFavorites'.$count.$tab.'" href="javascript:void(0);">
                  <img border="0" src="'.FRONT_SITE_URL.'www/images/images1/favoriteicon.png" title="Save as Favorite"> 
                </a>
                <a style="'.$user_un_favorite.'" title="Saved as Favorite" onclick="PeopleMedia.Connect.toggleFavorite(false, '.$item['user_id'].', '.$count.', \''.$tab.'\', \''.$connect.'\')" class="RemoveFromFavorites'.$count.$tab.'" href="javascript:void(0);">
                  <img border="0" src="'.FRONT_SITE_URL.'www/images/images1/favoritedicon.png" title="Saved as Favorite">   
                </a>
                
                <a href="'.FRONT_SITE_URL.'/user/profile/viewprofile?profile='.$item['user_id'].'"> <img border="0" src="'.FRONT_SITE_URL.'www/images/images1/messageicon.png" title="Send a Message"> </a> 
              </div>

            </div>

            <div class="profilerepeatcol3">
              <textarea rows="" cols="" class="connectWriteMessageTextArea" id="connectInlineMessage'.$count.$tab.'" maxlength="3000">Write a quick message...</textarea>

              <a title="Send" class="button_style_send" onclick="PeopleMedia.Connect.sendMessage(\''.$item['user_id'].'\', '.$count.', \''.$tab.'\', \''.$item['username'].'\', '.$tabEnum.', '.$filter.', 1, \''.$connect.'\', 25, \'None\');" id="SendMessageButtonLink" href="javascript:void(0);">Send</a> </div>
            <div class="profilerepeatcol4"> <a title="Delete '.$for_delete.'" onclick="PeopleMedia.Connect.removeItem('.$count.', \''.$tab.'\', \''.$connect.'\')" href="javascript:void(0);"><img border="0" class="hide1" src="'.FRONT_SITE_URL.'www/images/images1/hidebutton.png"></a> </div>
            <p class="clearfix">&nbsp;</p>
            <div style="display:none;" id="popupshowdelete'.$count.$tab.'" class="popupshowblock">
              <div class="overlayplace">
                <div class="popupshapestyle deleteactionoverlay">
                  <div class="largestclosebtn"> <a class="closebtn" onclick="PeopleMedia.Connect.hideRemoveItemPopup('.$count.', \''.$tab.'\')" title="Close" href="javascript:void(0);" id="PopupBlockCloseButton"><img border="0" src="'.FRONT_SITE_URL.'www/images/images1/largestclosebtn.png"></a> </div>
                  <div class="blockcontent">
                    <h1>Are you sure you want to delete <span id="PopupBlockUsernameSpan">this View</span>?</h1>
                    <div class="sharecontentbuttonarea">
                      <p class="blocklinksbtn">
                        <a onclick="PeopleMedia.Connect.deleteConnectItem('.$item['user_id'].', '.$count.', \''.$tab.'\', '.$tabEnum.', '.$filter.', 1)" href="javascript:void(0);">Delete</a>
                        <a class="button_style" onclick="PeopleMedia.Connect.hideRemoveItemPopup('.$count.', \''.$tab.'\')" href="javascript:void(0);">No</a>
                      </p>
                    </div>
                  </div>
                </div>
              </div>
              <div class="overlaywholescreen"></div>
            </div>

          </div>';
      $count++;
    endforeach;
    $html .= '</div>';
    return $html;
  }
  
  public function getHtmlMessageMemberList($rsUserView,$totalUserView,$currentPage,$tab,$tabEnum,$filter,$connect){
    $watched = 'Liked';
    $img_watched = 'facebooklikeicon.png';
    $for_delete = 'View';
    if($tab == 'Favorites'){
      $watched = 'Messaged';
      $img_watched = 'staricon.png';
      $for_delete = 'Favorite';
    }else if($tab == 'Yeses'){
      $watched = 'Yesed';
      $img_watched = 'checkicon.png';
      $for_delete = 'Yes';
    }
    $html = '<div id="connect'.$tab.'MemberList">';
    $count = 0;
    
    foreach($rsUserView as $item):
      $link_img = FRONT_SITE_URL . 'www/images/images1/noPhoto-1.gif';
      if ($item['link_img'] != null) 
        $link_img = FRONT_SITE_URL. 'www/uploads/photos/thumbs/thumb_'. $item['link_img']; 
      else {
        $link_img = $item['gender'] == 'male' ? FRONT_SITE_URL . 'www/images/images1/noPhoto-1.gif' : FRONT_SITE_URL . 'www/images/images1/noPhoto-2.gif';
      }
      $user_favorite = $item['user_favorited']!=null?'display:none':'display:inline';
      $user_un_favorite = $item['user_favorited']==null?'display:none':'display:inline';
      $html.='<div id="connectItem'.$count.$tab.'" class="profilerepeat ">
            <div class="profilerepeatcol0">
              <input type="checkbox" onchange="PeopleMedia.Connect.selectSingleDeleteCheckBox(\''.$tab.'\', '.$count.')" value="" class="deleteCheckbox'.$tab.'" id="checkboxDelete'.$count.$tab.'" name="'.$item['user_id'].'">
            </div>
            <div class="profilerepeatcol1 ">

              <div id="profileoverlayplace">
              </div>
              <a title="bighuggs1" href="'. FRONT_SITE_URL.'user/profile/viewprofile?profile='.$item['user_id'].'">
                                <img border="0" class="userpic" title="tuong" src="'.$link_img.'">
              </a>
            </div>
            <div class="profilerepeatcol2">
              <div class="profilerepeatcol2row1">
                <p><a href="'. FRONT_SITE_URL.'user/profile/viewprofile?profile='.$item['user_id'].'">'.$item['username'].'</a></p>
                <img src="'.FRONT_SITE_URL.'www/images/images1/'.$img_watched.'" title="Viewed">
                <p class="lightgraytext timestampcl">'.$watched.': '.changedDateFormat($item['date_view'],'d-m-Y').'</p>
              </div>


              <div class="profilerepeatcol2row2">

                <p>'.calculateYearOld($item['birthdate']).' | '.$item['country_name'].'                                              </p>
              </div>

              <div class="profilerepeatcol2row3">
                <p><span class="lightgraytext">Message: </span>
                  '.WordCut($item['text'],200,'...').'
              </p>
              <p>
                <span class="lightgraytext">
                  <a title="Send" onclick="PeopleMedia.Connect.showMessage(\''.$item['text'].'\')" href="javascript:void(0);">Show Message</a> 
                </span>
              </p>
              </div>

              <div class="profilerepeatcol2row4">
                
                <a style="'.$user_favorite.'" onclick="PeopleMedia.Connect.toggleFavorite(true, '.$item['user_id'].', '.$count.', \''.$tab.'\', \''.$connect.'\')" title="Save as Favorite" class="SaveToFavorites'.$count.$tab.'" href="javascript:void(0);">
                  <img border="0" src="'.FRONT_SITE_URL.'www/images/images1/favoriteicon.png" title="Save as Favorite"> 
                </a>
                <a style="'.$user_un_favorite.'" title="Saved as Favorite" onclick="PeopleMedia.Connect.toggleFavorite(false, '.$item['user_id'].', '.$count.', \''.$tab.'\', \''.$connect.'\')" class="RemoveFromFavorites'.$count.$tab.'" href="javascript:void(0);">
                  <img border="0" src="'.FRONT_SITE_URL.'www/images/images1/favoritedicon.png" title="Saved as Favorite">   
                </a>
                
                <a href="'.FRONT_SITE_URL.'/user/profile/viewprofile?profile='.$item['user_id'].'"> <img border="0" src="'.FRONT_SITE_URL.'www/images/images1/messageicon.png" title="Send a Message"> </a> 
              </div>

            </div>

            <div class="profilerepeatcol3">
              <textarea rows="" cols="" class="connectWriteMessageTextArea" id="connectInlineMessage'.$count.$tab.'" maxlength="3000">Write a quick message...</textarea>

              <a title="Send" class="button_style_send" onclick="PeopleMedia.Connect.sendMessage(\''.$item['user_id'].'\', '.$count.', \''.$tab.'\', \''.$item['username'].'\', '.$tabEnum.', '.$filter.', 1, \''.$connect.'\', 25, \'None\');" id="SendMessageButtonLink" href="javascript:void(0);">Send</a> </div>
            <div class="profilerepeatcol4"> <a title="Delete '.$for_delete.'" onclick="PeopleMedia.Connect.removeItem('.$count.', \''.$tab.'\', \''.$connect.'\')" href="javascript:void(0);"><img border="0" class="hide1" src="'.FRONT_SITE_URL.'www/images/images1/hidebutton.png"></a> </div>
            <p class="clearfix">&nbsp;</p>
            <div style="display:none;" id="popupshowdelete'.$count.$tab.'" class="popupshowblock">
              <div class="overlayplace">
                <div class="popupshapestyle deleteactionoverlay">
                  <div class="largestclosebtn"> <a class="closebtn" onclick="PeopleMedia.Connect.hideRemoveItemPopup('.$count.', \''.$tab.'\')" title="Close" href="javascript:void(0);" id="PopupBlockCloseButton"><img border="0" src="'.FRONT_SITE_URL.'www/images/images1/largestclosebtn.png"></a> </div>
                  <div class="blockcontent">
                    <h1>Are you sure you want to delete <span id="PopupBlockUsernameSpan">this View</span>?</h1>
                    <div class="sharecontentbuttonarea">
                      <p class="blocklinksbtn">
                        <a onclick="PeopleMedia.Connect.deleteConnectItem('.$item['user_id'].', '.$count.', \''.$tab.'\', '.$tabEnum.', '.$filter.', 1)" href="javascript:void(0);">Delete</a>
                        <a class="button_style" onclick="PeopleMedia.Connect.hideRemoveItemPopup('.$count.', \''.$tab.'\')" href="javascript:void(0);">No</a>
                      </p>
                    </div>
                  </div>
                </div>
              </div>
              <div class="overlaywholescreen"></div>
            </div>

          </div>';
      $count++;
    endforeach;
    $html .= '</div>';
    return $html;
  }
}